package routers

import (
	address2 "gin/app/http/controller/address"
	"gin/app/http/controller/admin/refresh"
	cart2 "gin/app/http/controller/cart"
	order2 "gin/app/http/controller/order"
	product2 "gin/app/http/controller/product"
	"gin/app/http/controller/public"
	"gin/app/http/controller/upload"
	user2 "gin/app/http/controller/user"
	"gin/app/http/middleware"
	"github.com/gin-gonic/gin"
)

func InitApi(r *gin.Engine) {

	apiv1(r) //提供给移动端的接口
	admin(r) //提供给后台的接口
}

func admin(r *gin.Engine) {
	admin := r.Group("/admin")
	admin.GET("refresh/productEs", refresh.ProductEs)
	admin.GET("refresh/productEsAll", refresh.ProductEsAll)
}

func apiv1(r *gin.Engine) {
	r.Use(middleware.Cors())
	api := r.Group("/api")
	v1 := api.Group("/v1")
	v1.Use(middleware.Decrypt)
	v1.POST("login", public.Login)      //登陆
	v1.GET("register", public.Register) //注册

	v1.Use(
		middleware.CheckToken,
		//middleware.CheckAuth,
	) //用户认证中间件

	//公共接口
	v1.POST("getPhoneNumber", public.GetPhoneNumber) //注册
	v1.POST("area", public.GetArea)                  //获取省市区

	//商品
	product := v1.Group("/product")
	product.POST("index", product2.Index)           //商品列表
	product.POST("detail", product2.Detail)         //商品详情
	product.POST("category", product2.CategoryList) //商品分类
	product.POST("search", product2.Search)         //商品搜索

	//订单
	order := v1.Group("/order")
	order.POST("create", order2.CreateOrder) //创建订单
	order.POST("lists", order2.GetOrderList) //订单列表

	//购物车
	cart := v1.Group("/cart")
	cart.POST("lists", cart2.GetCartList) //购物车列表
	cart.POST("add", cart2.AddCart)       //添加购物车
	cart.POST("remove", cart2.Remove)     //删除购物车项
	cart.POST("update", cart2.Update)     //更新购物车项

	//地址管理
	address := v1.Group("/address")
	address.POST("lists", address2.GetAdressList) //地址列表
	address.POST("create", address2.AddAdress)    //添加地址
	address.POST("remove", address2.Remove)       //删除地址
	address.POST("update", address2.Update)       //更新地址

	//用户信息
	user := v1.Group("/user")
	user.POST("getUserInfo", user2.GetUserInfo) //首页

	//文件上传
	api.POST("uploadFile", upload.UploadFile)
	api.POST("uploadFiles", upload.UploadFiles)

}
